<?php

namespace Alipay\AlipayAuth\Response;

use Alipay\Http\Response;

class AlipayAuthTokenListResponse extends Response
{
    private $msg;

    private $sign;

    private $userId;

    private $authAppId;

    private $expiresIn;

    private $authMethods;

    private $authStart;

    private $authEnd;

    public function resolve(): Response
    {
        parent::resolve();

        if (json_decode($this->getBody())) {
            $body = json_decode($this->getBody(), true);
            $this->setBody($body);
            $this->sign = $body['sign'] ?? '';
            $body = $body['alipay_open_auth_token_app_query_response'] ?? '';
            $code = $body['code'] ?? '';

            if ($code != '10000') {
                $this->setError(trim($this->msg . ' ' . ($body['sub_code'] ?? '') . ' ' . ($body['sub_msg'] ?? '')));
                return  $this;
            }
            $this->userId = $body['user_id'] ?? '';
            $this->authAppId = $body['auth_app_id'] ?? '';
            $this->expiresIn = $bodyv['expires_in'] ?? '';
            $this->authMethods = $body['auth_methods'] ?? '';
            $this->expiresIn = $body['expires_in'] ?? '';
            $this->authStart = $body['auth_start'] ?? '';
            $this->authEnd = $body['auth_end'] ?? '';

        } else {
            $this->setError($this->getBody());
        }
        return $this;
    }

    /**
     * @return mixed
     */
    public function getUserId()
    {
        return $this->userId;
    }

    /**
     * @return mixed
     */
    public function getAuthAppId()
    {
        return $this->authAppId;
    }

    /**
     * @return mixed
     */
    public function getExpiresIn()
    {
        return $this->expiresIn;
    }

    /**
     * @return mixed
     */
    public function getAuthMethods()
    {
        return $this->authMethods;
    }

    /**
     * @return mixed
     */
    public function getAuthStart()
    {
        return $this->authStart;
    }

    /**
     * @return mixed
     */
    public function getAuthEnd()
    {
        return $this->authEnd;
    }


}